package com.example.materialviewpagerdemo;

import android.content.Context;
import android.os.Handler;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.materialviewpagerdemo.bean.ManualMoudel;

import java.util.List;

public class ManualAdapter extends RecyclerView.Adapter<ManualAdapter.ManulViewHolder> {
    List<ManualMoudel> contents;
    Context context;

    public ManualAdapter(Context context, List<ManualMoudel> contents) {
        this.contents = contents;
        this.context=context;
    }
    public int getItemCount() {
        Log.i("nnnn", "getItemCount: "+contents.size());
        return contents.size();
    }

    @Override
    public ManulViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = null;
        view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.manual_view, parent, false);

        return new ManulViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ManulViewHolder holder, int position) {
        holder.imageView.setImageDrawable(context.getDrawable(contents.get(position).getImage_id()));
        holder.textView.setText(contents.get(position).getStrDiscription());
        holder.linearLayout.setOnClickListener(contents.get(position).getOnClickListener());
        Log.i("nnnn", "onBindViewHolder: "+contents.get(position).getStrDiscription()+""+position);
    }


    public class ManulViewHolder extends RecyclerView.ViewHolder
    {
        LinearLayout linearLayout;
        TextView textView;
        ImageView imageView;

        public ManulViewHolder(View itemView) {
            super(itemView);
            linearLayout=itemView.findViewById(R.id.collect_line);
            imageView=itemView.findViewById(R.id.collect);
            textView=itemView.findViewById(R.id.collect_fyy);
        }
    }
}
